<?php


namespace app\api\controller;


use app\BaseController;
use think\middleware\AllowCrossDomain;

class Auth extends BaseController
{
    protected $middleware = [AllowCrossDomain::class, \app\middleware\Auth::class];

    public function index()
    {

    }

    public function check()
    {
        $userid = (int)$this->request->post('userid', '');
        $controller = $this->request->post('controller', '');
        $action = $this->request->post('action', '');
        $module = \Menu::get($controller);
        if (!count($module)) {
            return $this->msg(0);
        }
        if (!$module['is_auth']) {
            return $this->msg(1);
        }
        if (!isset($module['power'][$action])) {
            return $this->msg(0);
        }
        if (!$module['power'][$action]['is_auth']) return $this->msg(1);

        $has_power = \think\facade\Db::name('access_back')->where(['userid' => $userid, 'controller' => $controller, 'action' => $action])->value('itemid');
        if (!$has_power) {
            return $this->msg(0, 'NO_RIGHT');
        }
        return $this->msg(1);
    }

    public function power()
    {

    }
}